import sys
from PySide6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, 
                           QHBoxLayout, QPushButton, QLabel, QFileDialog, 
                           QLineEdit, QSpinBox, QComboBox, QGroupBox,
                           QProgressBar, QMessageBox, QColorDialog, QGridLayout)
from PySide6.QtCore import Qt
from PySide6.QtGui import QFont, QIcon, QAction, QActionGroup
from PIL import Image, ImageDraw, ImageFont
import os
import resources

class WatermarkTool(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("图片水印工具V0.0.1")
        self.setMinimumSize(900, 600)
        self.setStyleSheet("""
            QMainWindow {
                background-color: #f8f9fa;
            }
            QGroupBox {
                font-weight: bold;
                border: 1px solid #dcdde1;
                border-radius: 10px;
                margin-top: 15px;
                padding: 20px;
                background-color: white;
                font-size: 16px;
            }
            QGroupBox::title {
                color: #343a40;
                padding: 0 15px;
                subcontrol-origin: margin;
                subcontrol-position: top left;
                left: 20px;
                top: 8px;
            }
            QPushButton {
                background-color: #228be6;
                color: white;
                border: none;
                padding: 10px 20px;
                border-radius: 8px;
                min-width: 120px;
                font-weight: bold;
                font-size: 15px;
            }
            QPushButton:hover {
                background-color: #1c7ed6;
            }
            QPushButton:pressed {
                background-color: #1971c2;
            }
            QPushButton#processBtn {
                background-color: #40c057;
                padding: 12px 30px;
                font-size: 17px;
            }
            QPushButton#processBtn:hover {
                background-color: #37b24d;
            }
            QLabel {
                font-size: 15px;
                color: #495057;
                font-weight: 500;
            }
            QLineEdit, QSpinBox, QComboBox {
                padding: 10px 15px;
                font-size: 15px;
                min-height: 35px;
                border: 2px solid #e9ecef;
                border-radius: 8px;
                background-color: white;
                color: #495057;
            }
            QLineEdit:focus, QSpinBox:focus, QComboBox:focus {
                border: 2px solid #228be6;
                box-shadow: 0 0 0 3px rgba(34, 139, 230, 0.15);
            }
            QLineEdit:hover, QSpinBox:hover, QComboBox:hover {
                border: 2px solid #74c0fc;
            }
            QProgressBar {
                border: none;
                border-radius: 8px;
                text-align: center;
                background-color: #e9ecef;
                height: 30px;
                font-size: 15px;
                color: white;
            }
            QProgressBar::chunk {
                background-color: #228be6;
                border-radius: 8px;
            }
            QMenuBar {
                background-color: white;
                border-bottom: 1px solid #e9ecef;
                padding: 8px;
                font-size: 15px;
            }
            QMenuBar::item {
                padding: 8px 15px;
                border-radius: 6px;
            }
            QMenuBar::item:selected {
                background-color: #e7f5ff;
                color: #228be6;
            }
            QMenu {
                background-color: white;
                border: 1px solid #e9ecef;
                border-radius: 8px;
                padding: 8px;
                font-size: 15px;
            }
            QMenu::item {
                padding: 8px 30px;
                border-radius: 6px;
            }
            QMenu::item:selected {
                background-color: #e7f5ff;
                color: #228be6;
            }
            QStatusBar {
                background-color: white;
                color: #495057;
                padding: 8px;
                border-top: 1px solid #e9ecef;
                font-size: 14px;
            }
            QSpinBox::up-button, QSpinBox::down-button {
                width: 25px;
                border: none;
                background-color: #f8f9fa;
            }
            QSpinBox::up-button:hover, QSpinBox::down-button:hover {
                background-color: #e7f5ff;
            }
            QSpinBox::up-arrow {
                image: url(:/icons/resources/up_arrow.png);
                width: 12px;
                height: 12px;
            }
            QSpinBox::down-arrow {
                image: url(:/icons/resources/down_arrow.png);
                width: 12px;
                height: 12px;
            }
            QComboBox::drop-down {
                border: none;
                width: 30px;
            }
            QComboBox::down-arrow {
                image: url(:/icons/resources/down_arrow.png);
                width: 12px;
                height: 12px;
            }
            QMessageBox {
                min-width: 400px;
            }
            QMessageBox QLabel {
                font-size: 14px;
            }
            QMessageBox QPushButton {
                min-width: 80px;
                min-height: 30px;
            }
            QMessageBox QIcon {
                width: 24px;
                height: 24px;
            }
        """)
        
        # 初始化变量
        self.image_files = []
        self.watermark_text = "请输入水印内容"
        self.watermark_color = (255, 255, 255)  # 默认白色
        self.max_text_length = 20  # 设置最大字符数
        
        self.init_ui()
    
    def init_ui(self):
        # 创建菜单栏
        menubar = self.menuBar()
        
        # 文件菜单
        file_menu = menubar.addMenu('文件')
        
        # 选择图片动作
        select_action = QAction('选择图片', self)
        select_action.setShortcut('Ctrl+O')
        select_action.setIcon(QIcon.fromTheme("document-open"))
        select_action.triggered.connect(self.select_files)
        file_menu.addAction(select_action)
        
        file_menu.addSeparator()
        
        # 退出动作
        exit_action = QAction('退出', self)
        exit_action.setShortcut('Ctrl+Q')
        exit_action.setIcon(QIcon.fromTheme("application-exit"))
        exit_action.triggered.connect(self.close)
        file_menu.addAction(exit_action)
        
        # 添加状态栏
        self.statusBar().showMessage('就绪')
        
        # 设置菜单
        settings_menu = menubar.addMenu('设置')
        
        # 添加配色子菜单
        theme_menu = settings_menu.addMenu('主题配色')
        
        # 添加不同的配色方案
        themes = {
            '蓝色主题': {
                'primary': '#228be6',
                'hover': '#1c7ed6',
                'pressed': '#1971c2',
                'border': '#e9ecef',
                'background': '#f8f9fa',
                'text': '#495057'
            },
            '紫色主题': {
                'primary': '#7950f2',
                'hover': '#6741d9',
                'pressed': '#5f3dc4',
                'border': '#e9ecef',
                'background': '#f8f9fa',
                'text': '#495057'
            },
            '绿色主题': {
                'primary': '#40c057',
                'hover': '#37b24d',
                'pressed': '#2f9e44',
                'border': '#e9ecef',
                'background': '#f8f9fa',
                'text': '#495057'
            }
        }
        
        # 创建主题切换动作组
        theme_group = QActionGroup(self)
        theme_group.setExclusive(True)
        
        # 添加主题选项
        for theme_name, colors in themes.items():
            theme_action = QAction(theme_name, self)
            theme_action.setCheckable(True)
            theme_action.setChecked(theme_name == '蓝色主题')
            theme_action.triggered.connect(lambda checked, t=theme_name, c=colors: self.apply_theme(t, c))
            theme_group.addAction(theme_action)
            theme_menu.addAction(theme_action)
        
        # 其他菜单项...
        settings_menu.addSeparator()
        
        # 清除所选图片
        clear_action = QAction('清除所选图片', self)
        clear_action.triggered.connect(self.clear_selection)
        settings_menu.addAction(clear_action)
        
        # 重置水印设置
        reset_action = QAction('重置水印设置', self)
        reset_action.triggered.connect(self.reset_settings)
        settings_menu.addAction(reset_action)
        
        # 帮助菜单
        help_menu = menubar.addMenu('帮助')
        
        # 使用说明
        help_action = QAction('使用说明', self)
        help_action.triggered.connect(self.show_help)
        help_menu.addAction(help_action)
        
        # 关于
        about_action = QAction('关于', self)
        about_action.triggered.connect(self.show_about)
        help_menu.addAction(about_action)
        
        central_widget = QWidget()
        self.setCentralWidget(central_widget)
        main_layout = QVBoxLayout(central_widget)
        main_layout.setSpacing(20)
        main_layout.setContentsMargins(20, 20, 20, 20)
        
        # 文件选择组
        file_group = QGroupBox("图片选择")
        file_layout = QVBoxLayout()
        
        file_select_layout = QHBoxLayout()
        self.file_label = QLabel("未选择文件")
        self.file_label.setStyleSheet("""
            color: #666666;
            font-size: 15px;
        """)
        select_btn = QPushButton("选择图片")
        select_btn.setIcon(QIcon.fromTheme("document-open"))
        select_btn.clicked.connect(self.select_files)
        file_select_layout.addWidget(self.file_label)
        file_select_layout.addWidget(select_btn)
        file_layout.addLayout(file_select_layout)
        file_group.setLayout(file_layout)
        main_layout.addWidget(file_group)
        
        # 水印设置组
        watermark_group = QGroupBox("水印设置")
        watermark_layout = QVBoxLayout()
        watermark_layout.setSpacing(15)
        watermark_layout.setContentsMargins(15, 20, 15, 15)
        
        # 创建一个网格布局来对齐标签和输入框
        form_layout = QGridLayout()
        form_layout.setSpacing(15)  # 设置网格间距
        
        # 设置列宽度策略
        form_layout.setColumnMinimumWidth(0, 150)  # 标签列最小宽度
        form_layout.setColumnMinimumWidth(1, 250)  # 输入框列最小宽度
        form_layout.setColumnStretch(2, 1)  # 第三列作为弹性空间
        
        # 统一标签样式
        label_style = """
            QLabel {
                font-size: 15px;
                padding-right: 10px;
            }
        """
        
        # 水印文字输入
        text_label = QLabel("水印文字:")
        text_label.setStyleSheet(label_style)
        text_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        self.text_input = QLineEdit(self.watermark_text)
        self.text_input.setFixedWidth(250)
        self.text_input.setMinimumHeight(35)
        self.text_input.setMaxLength(self.max_text_length)  # 设置最大字符数
        self.text_input.textChanged.connect(self.update_watermark_text)
        
        # 添加字符计数标签
        self.char_count_label = QLabel(f"0/{self.max_text_length}")
        self.char_count_label.setStyleSheet("""
            QLabel {
                color: #666666;
                font-size: 12px;
                padding-left: 5px;
            }
        """)
        
        # 创建一水平布局来放置输入框和计数标签
        text_input_layout = QHBoxLayout()
        text_input_layout.addWidget(self.text_input)
        text_input_layout.addWidget(self.char_count_label)
        text_input_layout.setSpacing(5)
        
        form_layout.addWidget(text_label, 0, 0)
        form_layout.addLayout(text_input_layout, 0, 1)  # 使用addLayout而不是addWidget
        
        # 文字大小设置
        size_label = QLabel("文字大小:")
        size_label.setStyleSheet(label_style)
        size_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        self.size_spin = QSpinBox()
        self.size_spin.setFixedWidth(250)
        self.size_spin.setMinimumHeight(35)
        self.size_spin.setRange(10, 200)
        self.size_spin.setValue(50)
        self.size_spin.setSuffix("px")
        # 修改SpinBox的样式
        spin_style = """
            QSpinBox::up-button, QSpinBox::down-button {
                width: 25px;
                border: none;
                background-color: #f8f9fa;
            }
            QSpinBox::up-button:hover, QSpinBox::down-button:hover {
                background-color: #e7f5ff;
            }
            QSpinBox::up-arrow {
                image: url(:/icons/resources/up_arrow.png);
                width: 12px;
                height: 12px;
            }
            QSpinBox::down-arrow {
                image: url(:/icons/resources/down_arrow.png);
                width: 12px;
                height: 12px;
            }
        """
        self.size_spin.setStyleSheet(spin_style)
        form_layout.addWidget(size_label, 1, 0)
        form_layout.addWidget(self.size_spin, 1, 1)
        
        # 颜色选择
        color_label = QLabel("文字颜色:")
        color_label.setStyleSheet(label_style)
        color_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        self.color_btn = QPushButton()
        self.color_btn.setFixedWidth(250)
        self.color_btn.setMinimumHeight(35)
        self.color_btn.setStyleSheet("""
            QPushButton {
                background-color: rgb(255, 255, 255);
                border: 2px solid #e9ecef;
                border-radius: 8px;
            }
            QPushButton:hover {
                border: 2px solid #74c0fc;
            }
        """)
        self.color_btn.clicked.connect(self.choose_color)  # 添加点击事件
        form_layout.addWidget(color_label, 2, 0)
        form_layout.addWidget(self.color_btn, 2, 1)
        
        # 位置选择
        position_label = QLabel("位置:")
        position_label.setStyleSheet(label_style)
        position_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        self.position_combo = QComboBox()
        self.position_combo.setFixedWidth(250)
        self.position_combo.setMinimumHeight(35)
        self.position_combo.addItems(["左上角", "右上角", "左下角", "右下角", "居中", "左斜角", "右斜角"])  # 添加选项
        self.position_combo.setStyleSheet("""
            QComboBox {
                padding: 5px 10px;
                font-size: 14px;
                border: 2px solid #e9ecef;
                border-radius: 8px;
                background-color: white;
            }
            QComboBox:hover {
                border: 2px solid #74c0fc;
            }
            QComboBox::drop-down {
                width: 40px;
                border: none;
                border-left: 2px solid #e9ecef;
            }
            QComboBox::down-arrow {
                image: url(:/icons/resources/down_arrow.png);
                width: 12px;
                height: 12px;
            }
            QComboBox:on {
                border: 2px solid #228be6;
            }
            QComboBox::drop-down:hover {
                background-color: #e7f5ff;
                border-top-right-radius: 8px;
                border-bottom-right-radius: 8px;
            }
            QComboBox QAbstractItemView {
                border: 2px solid #e9ecef;
                border-radius: 8px;
                background-color: white;
                selection-background-color: #e7f5ff;
                selection-color: #228be6;
                outline: none;
                padding: 5px;
            }
            QComboBox QAbstractItemView::item {
                height: 35px;
                padding: 8px 15px;
                border-radius: 4px;
            }
            QComboBox QAbstractItemView::item:hover {
                background-color: #e7f5ff;
                color: #228be6;
            }
            QComboBox QAbstractItemView::item:selected {
                background-color: #e7f5ff;
                color: #228be6;
            }
        """)
        form_layout.addWidget(position_label, 3, 0)
        form_layout.addWidget(self.position_combo, 3, 1)
        
        # 透明度设置
        opacity_label = QLabel("透明度:")
        opacity_label.setStyleSheet(label_style)
        opacity_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        self.opacity_spin = QSpinBox()
        self.opacity_spin.setFixedWidth(250)
        self.opacity_spin.setMinimumHeight(35)
        self.opacity_spin.setRange(0, 100)
        self.opacity_spin.setValue(50)
        self.opacity_spin.setSuffix("%")
        self.opacity_spin.setStyleSheet(spin_style)
        form_layout.addWidget(opacity_label, 4, 0)
        form_layout.addWidget(self.opacity_spin, 4, 1)
        
        # 添加表单布局到主布局
        watermark_layout.addLayout(form_layout)
        watermark_group.setLayout(watermark_layout)
        main_layout.addWidget(watermark_group)
        
        # 进度条
        self.progress_bar = QProgressBar()
        self.progress_bar.setVisible(False)
        main_layout.addWidget(self.progress_bar)
        
        # 处理按钮
        process_btn = QPushButton("开始处理")
        process_btn.setObjectName("processBtn")
        process_btn.setFixedHeight(45)
        process_btn.clicked.connect(self.process_images)
        main_layout.addWidget(process_btn)
    
    def select_files(self):
        files, _ = QFileDialog.getOpenFileNames(
            self,
            "选择图片文件",
            "",
            "图片文件 (*.png *.jpg *.jpeg *.bmp)"
        )
        if files:
            self.image_files = files
            self.file_label.setText(f"已选择 {len(files)} 个文件")
    
    def update_watermark_text(self, text):
        """更新水印文字内容"""
        if text:  # 确保文字不为空
            self.watermark_text = text
        else:
            self.watermark_text = "请输入水印内容"  # 默认文字
            
        # 更新字符计数
        self.char_count_label.setText(f"{len(text)}/{self.max_text_length}")
        
        # 如果超出限制，改变计数标签颜色
        if len(text) >= self.max_text_length:
            self.char_count_label.setStyleSheet("""
                QLabel {
                    color: #dc3545;
                    font-size: 12px;
                    padding-left: 5px;
                }
            """)
        else:
            self.char_count_label.setStyleSheet("""
                QLabel {
                    color: #666666;
                    font-size: 12px;
                    padding-left: 5px;
                }
            """)
    
    def choose_color(self):
        color = QColorDialog.getColor()
        if color.isValid():
            # 更新水印颜色（RGB元组）
            self.watermark_color = (color.red(), color.green(), color.blue())
            # 更新颜色按钮的背景色
            self.color_btn.setStyleSheet(f"""
                QPushButton {{
                    background-color: rgb({color.red()}, {color.green()}, {color.blue()});
                    border: 2px solid #e9ecef;
                    border-radius: 8px;
                }}
                QPushButton:hover {{
                    border: 2px solid #74c0fc;
                }}
            """)
            # 打印当前颜色值以便调试
            print(f"Selected color: RGB({color.red()}, {color.green()}, {color.blue()})")
    
    def get_font_path(self, font_name):
        # 获取程序运行目录
        if getattr(sys, 'frozen', False):
            # 打包后的路径
            base_path = sys._MEIPASS
        else:
            # 开发环境路径
            base_path = os.path.dirname(os.path.abspath(__file__))
        
        return os.path.join(base_path, font_name)
    
    def show_warning(self, title, message):
        msg = QMessageBox(self)
        msg.setIcon(QMessageBox.Warning)
        msg.setWindowTitle(title)
        msg.setText(message)
        msg.setStandardButtons(QMessageBox.Ok)
        msg.setStyleSheet("""
            QMessageBox {
                min-width: 300px;
            }
            QMessageBox QLabel {
                min-height: 40px;
            }
            QMessageBox QIcon {
                width: 24px;
                height: 24px;
            }
        """)
        msg.exec()
    
    def process_images(self):
        if not self.image_files:
            self.show_warning("警告", "请先选择图片文件！")
            return
            
        if not self.watermark_text or self.watermark_text.isspace():
            self.show_warning("警告", "请输入水印文字！")
            return
            
        self.statusBar().showMessage('正在处理...')  # 更新状态栏
        
        position_map = {
            "左上角": (10, 10),
            "右上角": (None, None),  # 动态计算
            "左下角": (None, None),  # 动态计算
            "右下角": (None, None),  # 动态计算
            "居中": (None, None),    # 动态计算
            "左斜角": "left_diagonal",
            "右斜角": "right_diagonal"
        }
        
        position_type = self.position_combo.currentText()
        position = position_map[position_type]
        opacity = self.opacity_spin.value() / 100
        
        # 显示进度条
        self.progress_bar.setVisible(True)
        self.progress_bar.setMaximum(len(self.image_files))
        self.progress_bar.setValue(0)
        
        # 保存成功的文件路径列表
        successful_paths = []
        
        # 在处理图片时打印使用的颜色值
        print(f"Using watermark color: RGB{self.watermark_color}")
        
        for i, image_path in enumerate(self.image_files):
            try:
                # 打开图片
                img = Image.open(image_path)
                if img.mode != 'RGBA':
                    img = img.convert('RGBA')  # 确保图片是RGBA模式

                # 创建绘图对象
                draw = ImageDraw.Draw(img)
                
                # 修改文字大小设置
                font_size = self.size_spin.value()  # 使用用户设置的字体大小
                try:
                    # 尝试使用系统中文字体
                    if os.name == 'nt':  # Windows系统
                        font = ImageFont.truetype(self.get_font_path("simhei.ttf"), font_size)
                    else:
                        font = ImageFont.truetype("/System/Library/Fonts/PingFang.ttc", font_size)
                except:
                    try:
                        # 备选中文字体
                        font = ImageFont.truetype(self.get_font_path("simsun.ttc"), font_size)
                    except:
                        try:
                            font = ImageFont.truetype(self.get_font_path("msyh.ttc"), font_size)
                        except:
                            font = ImageFont.load_default()
                            QMessageBox.warning(self, "警告", "未找到合适的中文字体，水印可能无法正确显示中文")
                
                # 计算文字大小
                text_bbox = draw.textbbox((0, 0), self.watermark_text, font=font)
                text_width = text_bbox[2] - text_bbox[0]
                text_height = text_bbox[3] - text_bbox[1]
                
                # 计算位置和绘制水印
                # 确保使用正确的颜色值和透明度
                color_with_opacity = (*self.watermark_color, int(255 * opacity))
                print(f"Final color with opacity: RGBA{color_with_opacity}")
                
                if position_type in ["左斜角", "右斜角"]:
                    # 创建一个新的透明图层
                    txt = Image.new('RGBA', img.size, (255, 255, 255, 0))
                    d = ImageDraw.Draw(txt)
                    
                    # 计算对角线长度，确保文字能完整显示
                    diagonal_length = int((img.size[0]**2 + img.size[1]**2)**0.5)
                    
                    # 在中心位置绘制文字
                    text_pos = ((img.size[0] - text_width) // 2, (img.size[1] - text_height) // 2)
                    d.text(text_pos, self.watermark_text, fill=color_with_opacity, font=font)
                    
                    # 根据方向旋转
                    angle = -45 if position_type == "左斜角" else 45
                    txt = txt.rotate(angle, expand=True)
                    
                    # 调整旋转后图层的位置
                    paste_x = (img.size[0] - txt.size[0]) // 2
                    paste_y = (img.size[1] - txt.size[1]) // 2
                    
                    # 创建新的透明图层用于粘贴
                    final_layer = Image.new('RGBA', img.size, (255, 255, 255, 0))
                    final_layer.paste(txt, (paste_x, paste_y))
                    
                    # 合并图层
                    img = Image.alpha_composite(img, final_layer)
                else:
                    # 根据位置类型计算具体坐标
                    if position_type == "右上角":
                        text_pos = (img.size[0] - text_width - 10, 10)
                    elif position_type == "左下角":
                        text_pos = (10, img.size[1] - text_height - 10)
                    elif position_type == "右下角":
                        text_pos = (img.size[0] - text_width - 10, img.size[1] - text_height - 10)
                    elif position_type == "居中":
                        text_pos = ((img.size[0] - text_width) // 2, (img.size[1] - text_height) // 2)
                    else:  # 左上角
                        text_pos = (10, 10)
                    
                    draw = ImageDraw.Draw(img)
                    draw.text(text_pos, self.watermark_text, fill=color_with_opacity, font=font)

                # 保存图片
                output_dir = os.path.join(os.path.dirname(image_path), "watermarked")
                os.makedirs(output_dir, exist_ok=True)
                output_path = os.path.join(output_dir, os.path.basename(image_path))
                
                # 根据文件扩展名决定保存格式
                file_ext = os.path.splitext(image_path)[1].lower()
                if file_ext in ['.jpg', '.jpeg']:
                    # JPEG不支持透明度，转换为RGB模式
                    rgb_image = Image.new('RGB', img.size, (255, 255, 255))
                    rgb_image.paste(img, mask=img.split()[3])  # 使用alpha通道作为mask
                    rgb_image.save(output_path, quality=95)
                else:
                    # PNG和其他格式保持RGBA模式
                    img.save(output_path)
                
                # 添加到成功列表
                successful_paths.append(output_path)
                
                # 更新进度条
                self.progress_bar.setValue(i + 1)
                QApplication.processEvents()
                
            except Exception as e:
                QMessageBox.warning(self, "错误", f"处理图片 {image_path} 时出错：{str(e)}")
        
        # 显示完成信息和输出路径
        if successful_paths:
            output_dir = os.path.dirname(successful_paths[0])
            message = f"水印添加完成！\n\n输出目录：\n{output_dir}\n\n成功处理 {len(successful_paths)} 个文件。"
            QMessageBox.information(self, "完成", message)
        
        self.progress_bar.setVisible(False)
        
        # 处理完成后更新状态栏
        self.statusBar().showMessage('处理完���')
    
    def clear_selection(self):
        self.image_files = []
        self.file_label.setText("未选择文件")
    
    def reset_settings(self):
        self.text_input.setText("水印文字")
        self.size_spin.setValue(50)
        self.watermark_color = (255, 255, 255)
        self.color_btn.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.position_combo.setCurrentIndex(0)
        self.opacity_spin.setValue(50)
    
    def show_help(self):
        help_text = """
使用说明：

1. 选择图片：
   - 点击"选择图片"按钮或使用Ctrl+O
   - 支持多选图片文件

2. 水印设置：
   - 输入水印文字
   - 调整文字大小
   - 选择文字颜色
   - 设置水印位置
   - 调整透明度

3. 处理：
   - 点击"开始处理"按钮
   - 处理后的图片将保存在原图片目录的watermarked文件夹中
"""
        QMessageBox.information(self, "使用说明", help_text)
    
    def show_about(self):
        about_text = """
图片水印工具 v1.0

功能点：
- 支持批量处理
- 自定义水印文字
- 可调整字体大小和颜色
- 支持多种位置选择
- 透明度可调

作者：luoyun
"""
        QMessageBox.about(self, "关于", about_text)
    
    def apply_theme(self, theme_name, colors):
        """应用主题配色"""
        style = f"""
            /* 全局样式 */
            QMainWindow {{
                background-color: {colors['background']};
            }}
            
            /* 按钮样式 */
            QPushButton {{
                background-color: {colors['primary']};
                color: white;
                border: none;
                padding: 10px 20px;
                border-radius: 8px;
                min-width: 120px;
                font-weight: bold;
                font-size: 15px;
            }}
            QPushButton:hover {{
                background-color: {colors['hover']};
            }}
            QPushButton:pressed {{
                background-color: {colors['pressed']};
            }}
            
            /* 输入框样式 */
            QLineEdit, QSpinBox, QComboBox {{
                border: 2px solid {colors['border']};
                color: {colors['text']};
            }}
            QLineEdit:focus, QSpinBox:focus, QComboBox:focus {{
                border: 2px solid {colors['primary']};
            }}
            
            /* 菜单样式 */
            QMenuBar::item:selected, QMenu::item:selected {{
                background-color: {colors['hover']};
                color: white;
            }}
            
            /* 进���条样式 */
            QProgressBar::chunk {{
                background-color: {colors['primary']};
            }}
            
            /* 分组框样式 */
            QGroupBox::title {{
                color: {colors['primary']};
            }}
        """
        
        # 更新样式
        self.setStyleSheet(self.styleSheet() + style)
        
        # 更新状态栏
        self.statusBar().showMessage(f'已切换到{theme_name}')

if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setStyle('Fusion')  # 使用Fusion风格
    window = WatermarkTool()
    window.show()
    sys.exit(app.exec()) 